package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.SetmealDish;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDishMapper {

    //关联套餐的菜品的数量
    Long getSetmealIdsByDishIds(List<Long> dishIds);

    //插入多个菜品
    void insertBatch(@Param("setmealDishes") List<SetmealDish> setmealDishes, @Param("setmealId") Long setmealId);

    //套餐分页查询
    Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    //根据id返回套餐中的菜品
    @Select("select * from setmeal_dish where setmeal_id = #{setmealId}")
    List<SetmealDish> selectById(Long setmealId);

    //根据id删除套餐中的菜品
    @Delete("delete from setmeal_dish where setmeal_id = #{setmealId}")
    void deleteById(Long setmealId);

    //查询菜品状态为启售的个数
    @Select("select count(*) from dish a left join setmeal_dish sd on a.status = #{status} and sd.setmeal_id = #{setmealId} where a.id = sd.dish_id")
    Long selectStatus(Long setmealId, Integer status);
}
